package com.qf.flowerlanguage.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.flowerlanguage.entity.User;
import com.qf.flowerlanguage.service.UserService;
import com.qf.flowerlanguage.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Objects;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/loginUser")
    @ResponseBody
    public UserVo loginUser(@RequestBody User user){
        QueryWrapper<User> userQW = new QueryWrapper<>();
        userQW.eq("uname",user.getUname()).eq("upassword",user.getUpassword());
        User user1 = userService.getOne(userQW);
        // 比较密码

        UserVo userVo = new UserVo();
        if (Objects.isNull(user1)){
            userVo.setStatus(false);
            userVo.setMessage("登录失败");
        }else {
            userVo.setStatus(true);
            userVo.setMessage("登录成功");
            userVo.setData(user1.getUname());
        }
        return userVo;
    }
}
